package tech.aistar.day04;

import java.util.Arrays;
import java.util.Date;

/**
 * 本类用来演示: 业务类
 *
 * @author: success
 * @date: 2022/7/21 3:59 下午
 */
@SuppressWarnings("all")
public class CustomerBiz {
    /**
     * 订单o加入到c里面的ordList中去
     * @param c 客户
     * @param o 订单
     *
     *      c.getOrdList   ->   null
     *
     *      ordList -> {o}
     *
     *
     *   BA - 需求分析师 - UML - 统一建模语言     依赖关系  关联  聚合    组合
     *          继承   实现
     */
    public void add(Customer c,Ord o){
        Ord[] ordList = c.getOrdList();

        if(null == ordList){
            ordList = new Ord[0];
        }
        //放一个,扩容一个,末尾放
        ordList = Arrays.copyOf(ordList,ordList.length+1);
        //末尾放
        ordList[ordList.length-1] = o;

        c.setOrdList(ordList);
    }

    public void printOrdList(Customer c){
        Ord[] ordList = c.getOrdList();
        if(null == ordList || ordList.length==0){
            System.out.println("sorry,该客户没有任何订单信息!");
            return;
        }
        System.out.println("\t订单信息如下:>");
        for (Ord ord : ordList) {
            System.out.println("\t"+ord);
        }
    }
}
@SuppressWarnings("all")
class CustomerBizTest{
    public static void main(String[] args) {
        //1. 创建一个客户
        Customer customer = new Customer(1,"admin","110",new Date());

        //2. 模拟几个订单信息
        Ord o1 = new Ord(1,"1001",0,100.0d,new Date());
        Ord o2 = new Ord(2,"1002",0,100.0d,new Date());
        Ord o3 = new Ord(3,"1003",0,200.0d,new Date());

        //3. 创建业务类
        CustomerBiz biz = new CustomerBiz();
        biz.add(customer,o1);
        biz.add(customer,o2);
        biz.add(customer,o3);

        biz.printOrdList(customer);
    }
}